package org.bet.utils;

import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;

import org.apache.commons.lang.StringUtils;

public class ReflectionUtils extends org.springframework.util.ReflectionUtils {

//	public static Class getParameterClassOf(Class clazz, int index) {
////	    ParameterizedType genericSuperclass = (ParameterizedType) clazz.getGenericSuperclass();
////        Type wantedClassType = genericSuperclass.getActualTypeArguments()[index];
////        if (wantedClassType instanceof ParameterizedType) {
////            return (Class) ((ParameterizedType) wantedClassType).getRawType();
////        } 
////        else {
////            return (Class) wantedClassType;
////        }
////        
//		TypeVariable[] tvs = clazz.getTypeParameters();
//		TypeVariable tv = tvs[index];
//		
//		Type[] bounds = tv.getBounds();
//		
//		return (Class) bounds[0];
//	 }

	public static Method getReadMethod(Class clazz, String propertyName) {
		Method method = ClassUtils.getMethodIfAvailable(clazz, "get" + StringUtils.capitalise(propertyName), null);
		if(method == null){
			method = ClassUtils.getMethodIfAvailable(clazz, "is" + StringUtils.capitalise(propertyName), null);
		}
		return method;
	}
}
